import { objDeepCopy,getDateString } from "@/assets/js/common.js";
let Controller = {
	created() {
		this.initdata();
	},
	activated() {
		this.initdata();
	},
	methods: {
		initdata() {
			this.Model.orderId = this.$route.query.id;		//订单id
			//this.requestDetail(this,this.Model.orderId);
		},
		//详情接口
		requestDetail(that,id) {
			this.$ajax({
				method: 'get',
				url:this.apiTest+'/supplier/whWarehouse/outStorageOrder/detail/'+id,
				//url:'/api/whWarehouse/outStorageOrder/detail/'+id,
			}).then((res)=>{
				var data = res.data;
				if(data.status == 200){
					var result = data.result;
					console.log(result)
					//应出商品
					that.Model.tableData = objDeepCopy(result.goodsOutList);
					//实出商品
					that.Model.tableDataOutNews = objDeepCopy(result.goodsActualOutList);
					//操作日志
					//that.Model.tableData4 = objDeepCopy(result.whWarehouseLogList);
					//表头信息
					that.Model.tabFormInline = [{
							label: '销售出库单号',
							value: result.outStorageNumber,
						},
						{
							label: '单据状态',
							value: result.status,
						},
					];
					//步骤条
					var stepData =  objDeepCopy(result.whWarehouseStatus);
					var stepArr = [];
					for (let i = 0; i < stepData.length; i++) {
						if(stepData[i].code == result.status){
							that.Model.stepOption.activeStep = i;
						}
						let obj = {
							title:stepData[i].codeName,
							description:stepData[i].createTime,
						}
						stepArr.push(obj);
					}
					that.Model.stepOption.step = objDeepCopy(stepArr);
					//出库单基础信息
					that.Model.tableFormInline = [{
							label: '出库单类型',
							value: result.orderType
						},
						{
							label: 'SAP销售订单',
							value: result.sapSaleNumber
						},
						{
							label: '销售订单',
							value: result.saleNumber
						},
						{
							label: '是否开票',
							value: result.isInvoice
						},
						{
							label: '来源渠道',
							value: result.originChannel
						},
						{
							label: '发货仓位',
							value: result.deliverySpace
						},
						{
							label: '是否签名',
							value: result.isSign
						},
						{
							label: '创建人',
							value: result.createBy
						},
						{
							label: '操作人',
							value: result.operator
						},
						{
							label: '打印次数',
							value: result.printNo
						},
						{
							label: '备注',
							value: result.remark
						}
					];
					//个人信息（旧）
					that.Model.tableFormInline2 = [{
							label: '收件人姓名',
							value: result.userInfoLeft.receiveName
						},
						{
							label: '收件人手机号',
							value: result.userInfoLeft.receivePhone
						},
						{
							label: '收货人详细地址',
							value: result.userInfoLeft.receiveAddress
						},
					];
					//个人信息（新）
					if(!Object.keys(result.userInfoRight).length==0){
						that.Model.AdressChange = true;
						that.Model.tableFormInlineNew = [{
								label: '收件人姓名',
								value: result.userInfoRight.receiveName
							},
							{
								label: '收件人手机号',
								value: result.userInfoRight.receivePhone
							},
							{
								label: '收货人详细地址',
								value: result.userInfoRight.receiveAddress
							},
						];
					}
					//实出包材
					if(result.materialStandardList.length){
						that.Model.tableData2Out = objDeepCopy(result.materialStandardList);
					}
					//实出包材详情
					if(result.materialActualOutList.length){
						that.Model.PackmaterNewsStatus = true;
						that.Model.tableData2News = objDeepCopy(result.materialActualOutList);
					}
					//判断有无物流
					if(result.logisticsCompany){
						that.Model.interflow = true;
						that.Model.interflowcompany = result.logisticsCompany;
					}
					if(result.trackingNumber){
						that.Model.interflow = true;
						that.Model.interflownumber = result.trackingNumber;
					}
					//判读是否出现创建物流按钮
					that.Model.logisticsBtn = result.isCreateLogistics;
				}else{
					that.tips(that,'warning',data.msg)
				}
			
			});
		},
		warehousing(row) {
			this.Model.warehousingDialogStatus = row.status;
			this.Model.warehousingDialogFlag = true;
		},
		handleSelectionChange(val) {
			this.Model.TableSelectData = val;
		},
		materialSelectionChange(val) {
			console.log(val);
		},
		handleCurrentChange(val) {
			this.Model.pager.params.pageIndex = val;
		},
		handleSizeChange(val) {
			this.Model.pager.params.pageSize = val;
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		onTabChange(val) {
			switch (val) {
				case 1:
				break;
				case 2:
				break;
				case 3:
				break;
			}	
		},
		//展开收缩
		toggleTableDetail(val) {
			const obj = this.Model[val];
			if (obj.flag === true) {
				this.Model[val].src = require('@/assets/img/icon_collapse.png');
				this.Model[val].flag = false;
			} else {
				this.Model[val].src = require('@/assets/img/icon_unfold.png');
				this.Model[val].flag = true;
			}
		},
		tips(that,type,message) {
			that.$message({
				message: message,
				type: type
			});
		},
	},
}
export default Controller;
